#pragma once

class MarshalUtils sealed 
{
public:


	static System::Guid GetCLRGuid(GUID guid)
	{
		 return System::Guid( guid.Data1, guid.Data2, guid.Data3, 
                guid.Data4[ 0 ], guid.Data4[ 1 ], 
                guid.Data4[ 2 ], guid.Data4[ 3 ], 
                guid.Data4[ 4 ], guid.Data4[ 5 ], 
                guid.Data4[ 6 ], guid.Data4[ 7 ] );
	}

	static GUID GetNativeGUID(System::Guid guid)
	{
		array<System::Byte>^ guidData = guid.ToByteArray();
		pin_ptr<const System::Byte> data = &(guidData[0]);
		GUID nguid = *((const GUID *)data);

		return nguid;
		
	}

	static void GetNativeLPCTSTR(System::String ^str, TCHAR * buf)
	{
		TCHAR * pName = (TCHAR *)(void *)(System::Runtime::InteropServices::Marshal::StringToHGlobalAuto(str));
		_tcscpy_s(buf,str->Length + 1,pName);
		System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr)pName);
	}

	static System::String ^ GetCLRString(LPCTSTR str)
	{
		return gcnew System::String(str);
	}

	static CString GetMFCString(System::String ^str)
	{
		TCHAR * pName = (TCHAR *)(void *)(System::Runtime::InteropServices::Marshal::StringToHGlobalUni(str));
		CString nstr(pName);
		System::Runtime::InteropServices::Marshal::FreeHGlobal((System::IntPtr)pName);
		return nstr;

	}



};
